﻿/******************************************************************************
 * Name         : TimeUtil.cpp
 * Author       : 671643387
 * Date         : 2015年9月6日
 * Description  :
 *****************************************************************************/

#include <stdarg.h>
#include <iostream>
#include "dev/base/Console.hpp"
#include "dev/base/Logger.hpp"
#include "dev/base/TimeUtil.hpp"
#include "dev/base/Thread.hpp"
using namespace dev::base;

void print_vargs(const char* format, va_list arg)
{
    char buff[0x4000] = { 0 };
    vsnprintf(buff, sizeof(buff), format, arg);
    std::cout << dev::base::TimeUtil::fromStartup()
        << "," << dev::base::Thread::currentTid() << "," << buff << std::endl;
}

Logger::Logger()
{

}

Logger::~Logger()
{

}

void Logger::log(const char* format, ...)
{
    va_list arg;
    va_start(arg, format);
    print_vargs(format, arg);
    va_end(arg);
}

void Logger::warning(const char* format, ...)
{
    set_console_color(CONSOLE_COLOR_FOREGROUND_INTENSITY | CONSOLE_COLOR_FOREGROUND_YELLOW);

    va_list arg;
    va_start(arg, format);
    print_vargs(format, arg);
    va_end(arg);

    set_console_color(CONSOLE_COLOR_FOREGROUND_WHITE);
}

void Logger::error(const char* format, ...)
{
    set_console_color(CONSOLE_COLOR_FOREGROUND_INTENSITY | CONSOLE_COLOR_FOREGROUND_RED);

    va_list arg;
    va_start(arg, format);
    print_vargs(format, arg);
    va_end(arg);

    set_console_color(CONSOLE_COLOR_FOREGROUND_WHITE);
}
